package cn.bellychang.leetcode.question230;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2021/3/17
 */
public class Solution {

    public int kthSmallest(TreeNode root, int k) {

        List<Integer> result = new ArrayList<>();
        inOrderTraverse(root, result);
        return result.get(k - 1);
    }

    private void inOrderTraverse(TreeNode treeNode, List<Integer> result) {
        if (treeNode==null) {
            return;
        }
        inOrderTraverse(treeNode.left, result);
        result.add(treeNode.val);
        inOrderTraverse(treeNode.right, result);
    }
}
